#ifndef CPP_MAIN_WINDOW_H
#define CPP_MAIN_WINDOW_H

#include <Global.h>
#include <MiniGui.h>
#include <vector>

class Activity;
class View;

//@brief 主窗口
//@author cvte
//@description 每个应用唯一
class MainWindow {
   public:
    typedef enum {
        ACTIVITY_CONTROL_NONE,
        ACTIVITY_CONTROL_START, //开始一个Activity
        ACTIVITY_CONTROL_STOP, //退出一个Activity
        ACTIVITY_CONTROL_STOP_TOP_AND_START, //退出栈顶Activity并开始一个Activity
        ACTIVITY_CONTROL_STOP_ALL_AND_START, //退出所有Activity并开始一个Activity，如果Activity已存在，不会重新创建，只恢复
        ACTIVITY_CONTROL_COUNT
    } ACTIVITY_CONTROL;

    friend class PowerManager;
    friend class UpgradeService;

    typedef std::vector<View*> ViewVector;
    typedef std::pair<std::string, ACTIVITY_CONTROL> ActivityControlMap;
    typedef std::vector<ActivityControlMap> ActivityControlVector;

    MainWindow();
    virtual ~MainWindow();
    int start();
    //@method 关闭主窗口
    void close();
    HWND getHWND();
    //@method 刷新界面
    void invalidate();
    //@method 切换Activity
    void switchActivity(ACTIVITY_CONTROL control, const std::string& activityName);
    void switchActivity(ACTIVITY_CONTROL control, Activity* activity);
    //@method 异步地delete View，一般用于点击按钮时触发删除界面的逻辑中
    void deleteViewAsync(View* view);

    static LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

   protected:
    virtual void onCreate();
    bool onWindowControlProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
    //@method 发送系统睡眠消息（MiniGUI消息队列）
    void sendSystemSleepMessage();
    void exitAndSwitchToUpgrade();

   private:
    //按钮组件的窗口句柄
    HWND mHwnd;
    ViewVector mViewShouldDelete;
    ActivityControlVector mActivityControl;
    bool mShouldExitAndSwitchToUpgrade = false;
};

#endif /* CPP_MAIN_WINDOW_H */